<?php
$this->template->add_admin_js_lib('http://code.jquery.com/ui/1.10.1/jquery-ui.js');
$this->template->add_admin_js_lib(admin_theme_url()."vendor/jquery-tree/js/jquery.tree.js");
//$this->template->add_admin_js_lib(admin_theme_url()."vendor/jquery-tree/js/jquery.treecheckbox.js");
//$this->template->add_admin_js_lib(admin_theme_url()."vendor/jquery-tree/js/jquery.treecollapse.js");
//$this->template->add_admin_js_lib(admin_theme_url()."vendor/jquery-tree/js/jquery.treednd.js");

$this->template->add_admin_css_lib('http://code.jquery.com/ui/1.10.1/themes/base/jquery-ui.css');
$this->template->add_admin_css_lib(admin_theme_url()."vendor/jquery-tree/css/jquery.tree.css");
// $GLOBALS['selected'] = $selected;
// $GLOBALS['menu_tree'] = $menu_tree;
$is_expanded = '';

$selected = array_unique($selected);
// prd($selected);
// $selected = array(65);
// $is_expanded = checkExpanded($menu_tree,$selected, $menu_tree);
if(is_array($is_expanded))
{
    $checkExpanded = array_unique($is_expanded);
}
else
{
    $checkExpanded = array();
}
// $checkExpanded = array_unique(checkExpanded($menu_tree,$selected, $menu_tree));
?>
<div id='<?php echo @$list_id; ?>' class="checkbox-tree well well-sm list-cat-post">
	<ul>
		<?php if (isset($menu_tree) && $menu_tree) foreach ($menu_tree as $menu) print_menu($menu, $list_id,$selected,  $checkExpanded); ?>
	</ul>
</div>

<script type="text/javascript">

$(document).ready(function() {
	$('.checkbox-tree').tree({
        onCheck: {
            node: 'expand',
            ancestors: 'checkIfFull',
            descendants: null,
            ancestors: null
        },
        onUncheck: {
            node: 'expand',
            ancestors: null,
            descendants: null
        },
        dnd: false
        //collapseUiIcon: 'ui-icon-plus',
        //expandUiIcon: 'ui-icon-minus',
        //leafUiIcon: 'ui-icon-bullet'
    });
});
</script>
<style type="text/css" media="screen">
	.checkbox-tree {
		max-height: 200px;
		overflow-y: scroll;
	}
</style>